import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../page/index.vue'
import login from '../page/login.vue'
import HomeIndexPage from '../page/HomePageFolder/index.vue'
import UserIndexPage from '../page/UserFolder/index.vue'
import ForumIndexPage from '../page/ForumPageFolder/index.vue'
import PhotoIndexPage from '../page/PhotoPageFolder/index.vue'
import PhotoDetail from '../page/PhotoPageFolder/PhotoDetail.vue'
import addPhotosPage from '../page/PhotoPageFolder/addPhotos.vue'
import TalkIndexPage from '../page//TalkPageFolder/index.vue'
import ConfessionIndexPage from '../page/ConfessionPageFolder/index.vue'
import userinfoPage from '../page/UserFolder/userinfo.vue'
import { Message } from 'element-ui'
import store  from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect: "/index/HomeIndexPage"
  },
  {
    path:"/login",
    component:login,
    name:"login",
    meta:{auth:false,name:"用户登录"}
  },
  {
    path:"/index",
    component:index,
    name:'index',
    meta:{auth:false},
    children:[
      {
        path:'TalkDetail',
        component:()=>import("@/page/TalkPageFolder/TalkDetail"),
        meta:{
          auth:false,name:'论坛详情'
        }
      },
      {
        path:'PostDetail',
        component:()=>import("@/page/PostFolder/PostDetail"),
        meta:{
          auth:false,
          name:'帖子详情'
        }
      },
      {
        path:"",
        redirect: "HomeIndexPage"
      },
      {
        path:"UserIndexPage",
        component:UserIndexPage,
        name:'UserIndexPage',
        meta:{auth:true,name:"用户信息"},
        children:[
          {
            path:"UserIndexDetailPage",
            component: userinfoPage,
            name:'UserDetail',
            meta:{auth:true,name:"用户详情"},
          },
          {
            path:"lzgl",
            component: () => import('@/page/UserFolder/lzgl.vue'),
            name:'lzgl',
            meta:{auth:true,name:"论坛管理"},
          },
          {
            path:"bbqgl",
            component: () => import('@/page/UserFolder/bbqgl.vue'),
            name:'bbqgl',
            meta:{auth:true,name:"我发布的表白墙"},
          },
          {
            path:"zpqgl",
            component: () => import('@/page/UserFolder/zpqgl.vue'),
            name:'zpqgl',
            meta:{auth:true,name:"我发布的照片墙"},
          }
        ],
      },
      {
        path:"HomeIndexPage",
        component:HomeIndexPage,
        name:'HomeIndexPage',
        meta:{auth:false,name:"首页"},
      },
      {
        path:"ForumIndexPage",
        component:ForumIndexPage,
        name:'ForumIndexPage',
        meta:{auth:false,name:"项目介绍"},
      },
      {
        path:"PhotoIndexPage",
        component:PhotoIndexPage,
        name:'PhotoIndexPage',
        meta:{auth:false,name:"校园照片墙"},
      },
      {
        path:"PhotoDetail",
        component:PhotoDetail,
        name:'PhotoDetail',
        meta:{auth:false,name:"照片墙详情"},
      },
      {
        path:"addPhotosPage",
        component:addPhotosPage,
        name:'addPhotosPage',
        meta:{auth:false,name:"留下足迹"},
      },
      {
        path:"TalkIndexPage",
        component:TalkIndexPage,
        name:'TalkIndexPage',
        meta:{auth:false,name:"校园聊斋"},
      },
      {
        path:"ConfessionIndexPage",
        component:ConfessionIndexPage,
        name:'ConfessionIndexPage',
        meta:{auth:false,name:"校园表白墙"},
      },

      {
        path: 'ConfessionIndexPage_detail',
        component: () => import('@/page/ConfessionPageFolder/detail'),
        name: 'VindicateDetail',
        meta: { auth: false, name: '表白墙详情' }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

// 前置路由守卫守卫
router.beforeEach((to,from,next)=>{
  if(to.meta.auth == true){
    // 查看是否登录
    if(store.state.user.token!=null){
      next()
    }else{
      Message.error("未检测到登录状态,请登录后再执行相关操作")
    }
  }else{
    next()
  }

})
// 全局后置路由守卫
router.afterEach((to,from,next)=>{
  document.title =  to.meta.name
})


export default router
